package com.isunland.managesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.rBuyappSub;
import java.util.ArrayList;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2017/6/16 15:35
 */
public class BuyDetailListAdapter<T> extends BaseAdapter {
  private final Context context;
  private ArrayList<T> objects = new ArrayList<>();
  private LayoutInflater layoutInflater;

  public BuyDetailListAdapter(Context context, ArrayList<T> objects) {
    this.context = context;
    this.layoutInflater = LayoutInflater.from(context);
    this.objects = objects;
  }

  @Override public int getCount() {
    return objects.size();
  }

  @Override public T getItem(int position) {
    return objects.get(position);
  }

  @Override public long getItemId(int position) {
    return position;
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
      convertView = layoutInflater.inflate(R.layout.adapter_locale_work_query_count, parent, false);
      convertView.setTag(new ViewHolder(convertView));
    }
    initializeViews(getItem(position), (ViewHolder) convertView.getTag());
    return convertView;
  }

  private void initializeViews(T object, ViewHolder holder) {
    rBuyappSub item = (rBuyappSub) object;
    //holder.ivLogo.setImageResource(R.drawable.ic_knowledge);
    holder.ivLogo.setVisibility(View.GONE);
    holder.tvTitle.setText(item.getMaterialKindName());//物料类别
    holder.tvContent.setText(item.getMaterialName());//物料名称
    holder.tvBottomLeft.setText(item.getRegDate());//登记时间
    holder.tvBottomRight.setText(item.getRegStaffName());//登记人
  }

  static class ViewHolder {
    @BindView(R.id.iv_logo) ImageView ivLogo;
    @BindView(R.id.tv_bottomLeft) TextView tvBottomLeft;
    @BindView(R.id.tv_title) TextView tvTitle;
    @BindView(R.id.tv_content) TextView tvContent;
    @BindView(R.id.tv_contentRight) TextView tvContentRight;
    @BindView(R.id.tv_bottomRight) TextView tvBottomRight;

    ViewHolder(View view) {
      ButterKnife.bind(this, view);
    }
  }
}
